﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.Organization.Read.API.Application.Command.FieldSettingCommand;
using S.Organization.Read.API.Application.Command.SupplierCommand;

namespace S.Organization.Read.API.Controllers
{
    /// <summary>
    /// 供应商管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SupplierController : ControllerBase
    {
        private readonly IMediator _mediator;

        public SupplierController(IMediator mediator)
        {
            _mediator = mediator;
        }



        /// <summary>
        /// 获取供应商数据
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> HandleGetSupplier([FromQuery] GetSupplierCommand request, CancellationToken cancellationToken)
        {
            return Ok(await _mediator.Send(request));
        }

        /// <summary>
        /// 获取供应商数据
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> SleectSupplier([FromQuery] SelectSupplierCommand request, CancellationToken cancellationToken)
        {
            return Ok(await _mediator.Send(request));
        }

        /// <summary>
        /// 根据Id获取供应商数据
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetByIdSupplier([FromQuery] GetSupplierByIdCommand request, CancellationToken cancellationToken)
        {
            return Ok(await _mediator.Send(request));
        }



    }
}
